// 属性递归
export function convertToTree(departments, pid = 0) {
  const tree = []
  const children = departments.filter(dept => dept.pid === pid)

  children.forEach(child => {
    const childrenTree = convertToTree(departments, child.id)
    if (childrenTree.length) {
      child.children = childrenTree
    }
    tree.push(child)
  })

  return tree
}

